const http = require("http");
const fs = require("fs");
const path = require("path");
http.createServer((req, res) => {
    let filePath = path.join(__dirname, "线性铜币.png");
    let fileContent = fs.readFileSync(filePath);//得到的是图片的buffer数据
    // console.log(fileContent);
    //获取图片的base64数据
    fileContent = fileContent.toString("base64");//得到图片的base64编码数据
    let imgSrc = 'data: image/png; base64,' + fileContent;
    let imgStr = "<img src='" + imgSrc + "'/>";
    let htmlStr = "<!DOCTYPE html>" +
        "<html>" +
        "<head></head>" +
        "<body>" +
        imgStr +
        "</body>" +
        "</html>";
    //响应头
    res.writeHead(200, { "Content-Type": "text/html;charset=utf8" })
    res.end(htmlStr);
}).listen(8080);

console.log("server is listening 8080");